<template>
  <div id="app" @click="RefreshLock" @keypress="RefreshLock">
      <input id="copydiv" style="position: absolute; top: -1000px" />
      <router-view></router-view>
      <!-- <el-dialog :append-to-body="true" width="900px" title="报告预览" :visible.sync="prePDFVisible" @closed="clearPrePDF">
          <div style="height: 600px;">
              <pdf v-for="i in pdfPages" :key="i" :src="url" :page="i"></pdf>
          </div>
      </el-dialog> -->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="故障警告" :visible.sync="networkAlertMsg" width="700px">
          <div style="height: 50px;color:red;font-size:22px;text-align:center;">
              检测到网络故障，无法链接服务器，请检查网络或联系管理员！
          </div>
          <div style="margin-top:5px;text-align:right;margin-right:5px;">
              <button type="button" class="el-button el-button--default el-button--small" @click="networkAlertConfirm()">
                  <span>
                      确定
                  </span>
              </button>
          </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="系统升级提示" :visible.sync="ruimeiwaitreloading" width="500px">
          <div style="height: 50px;color:green;font-size:22px;text-align:center;line-height:50px;margin-top:10px;">
              系统已升级，点击确定后转入新版本！
          </div>
          <div style="margin-top:5px;text-align:right;margin-right:5px;">
              <button type="button" class="el-button el-button--default el-button--small" @click="waitReloadConfirm()">
                  <span>
                      确定
                  </span>
              </button>
          </div>
      </el-dialog>
      <el-dialog :append-to-body="true" width="900px" title="今日报阳未处理提示" :visible.sync="bactalertVisible" v-if="bactalertVisible">
          <rm-bactalert :alertlist="sampleList"></rm-bactalert>
      </el-dialog>
      <!--获取商品过期信息,低于安全库存警告信息，库存超限警告信息-->
      <el-dialog :append-to-body="true" width="1000px" title="商品库存自动报警" :visible.sync="invalertVisible" v-if="invalertVisible" v-el-drag-dialog :close-on-click-modal="false">
          <rm-invalert :expirydata="expirydata" :exceeddata="exceeddata" :fewerdata="fewerdata" :havedataqty="havedataqty"></rm-invalert>
      </el-dialog>
      <!--设备保养计划自动提醒-->
      <el-dialog :append-to-body="true" width="1170px" title="设备保养计划自动提醒" :visible.sync="devhandexeVisible" v-el-drag-dialog :close-on-click-modal="false">
          <div style="height:400px;" :key="devobj.plankey">
              <rm-devalert :tabledata="devobj.tabledata" @change="devhandexeVisible=false"></rm-devalert>
          </div>
      </el-dialog>
      <!--输血科异常提醒-->
      <el-dialog :append-to-body="true" width="900px" title="输血科异常提醒" :visible.sync="nbsalertVisible" v-if="nbsalertVisible" v-el-drag-dialog :close-on-click-modal="false">
          <rm-nbsalert :havedataqty="havedataqty" :overtimedata="overtimedata" :stocklimitdata="stocklimitdata" :specdata="specdata"></rm-nbsalert>
      </el-dialog>
      <!--消息弹窗提醒-->
      <el-dialog :append-to-body="true" width="1050px" :title="msgobj.params.title" :visible.sync="msgobj.msgdialog" v-el-drag-dialog :close-on-click-modal="false">
          <div style="height:400px;" :key="msgobj.msgkey">
              <rm-msgalert :params="msgobj.params" @change="msgobj.msgdialog=false"></rm-msgalert>
          </div>
      </el-dialog>
      <!--申请单计价失败消息提醒-->
      <el-dialog :append-to-body="true" width="1050px" title="申请单计价失败消息提醒" :visible.sync="reqchargeobj.msgdialog" v-if="reqchargeobj.msgdialog" v-el-drag-dialog :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
          <div style="height:400px;">
              <rm-reqchargealertinfo :tabledata="reqchargeobj.reqchargedatas" :params="reqchargeobj.params" :isrptadmin="rptadmin" @change="CloseMsgHandle"></rm-reqchargealertinfo>
          </div>
      </el-dialog>
      <el-dialog :append-to-body="true" width="1050px" title="用血计价失败消息提醒" :visible.sync="Bldchargeobj.msgdialog" v-el-drag-dialog :close-on-click-modal="false" @close="CloseMsgHandle('bldcharge',Bldchargeobj.params)" v-if="Bldchargeobj.msgdialog">
          <div style="height:600px;">
              <RmBldchargealertinfo :tabledata="Bldchargeobj.bldchargedatas" :params="Bldchargeobj.params" @change="CloseMsgHandle" :coldate ="Bldchargeobj.setdata"></RmBldchargealertinfo>
          </div>
      </el-dialog>
      <!--安全保护-->
      <el-dialog :append-to-body="true" title="安全保护" :visible.sync="scurity.dialogscurity" class="scurityclass" v-el-drag-dialog :close-on-click-modal="false" :show-close="false" width="610px">
          <div style="height:363px;width:600px">
              <RmScurityalertinfo @change="scurityEvent" :key="scurity.scuritykey"></RmScurityalertinfo>
          </div>
      </el-dialog>
      <!--待审核报告自动提醒-->
      <el-dialog :append-to-body="true" width="1050px" title="待审核报告自动提醒" :visible.sync="checkReportVisible" v-el-drag-dialog :close-on-click-modal="false">
          <div style="height:400px;" :key="reportobj.reportkey">
              <rm-reportalert :tabledata="reportobj.tabledata" @change="checkReportVisible=false"></rm-reportalert>
          </div>
      </el-dialog>
      <!--必须确认消息弹窗提醒-->
      <el-dialog :append-to-body="true" width="1050px" title="须确认消息自动提醒" :visible.sync="mustmsgobj.confirmVisible" v-el-drag-dialog :close-on-click-modal="false">
          <div style="height:630px;" :key="mustmsgobj.confirmkey">
              <rm-msgcenterpage :mustConfirmmsgData="mustmsgobj.tableData" @change="mustmsgobj.confirmVisible=false"></rm-msgcenterpage>
          </div>
      </el-dialog>
      <!-- <el-dialog el-dialog title="消息查看" :visible.sync="showsxkmsg" width="900px" v-el-drag-dialog :close-on-click-modal="false" v-if="showsxkmsg">
          <div style="height:40px;border:1px solid #CCC;line-height:35px;border-bottom:0">
              <table style="padding-top:0px;border-spacing:0px;width:100%">
                  <tr>
                      <td>
                          <el-radio-group v-model="Msg_type" @change="Msgtype_change">
                              <el-radio-button :label="'ALL'" border>全部:{{Msg_cnt.cnt}}</el-radio-button>
                              <el-radio-button :label="'04'" border>待审核:{{Msg_cnt.checkcnt}}</el-radio-button>
                              <el-radio-button :label="'08'" border>待接收:{{Msg_cnt.rcvcnt}}</el-radio-button>
                              <el-radio-button :label="'21'" border>待处置:{{Msg_cnt.buliangcnt}}</el-radio-button>
                              <el-radio-button :label="'15'" border>待评价:{{Msg_cnt.pijiacnt}}</el-radio-button>
                              <el-radio-button :label="'13'" border>用血通知:{{Msg_cnt.noticecnt}}</el-radio-button>
                              <el-radio-button :label="'OTHER'" border>其他:{{Msg_cnt.othercnt}}</el-radio-button>
                          </el-radio-group>

                      </td>
                      <td style="width:80px"></td>
                      <td style="width:80px">
                          <el-button style="width:72px" v-if="Msg_type=='04' && Msgdata.length >0 " @click="$router.push('/NBS512');showsxkmsg=false">审核</el-button>
                          <el-button style="width:72px" v-if="Msg_type=='08' && Msgdata.length >0 " @click="Batch_rcv">接收</el-button>
                          <el-button style="width:72px" v-if="Msg_type=='15' && Msgdata.length >0 " @click="$router.push('/NBS514');showsxkmsg=false">评价</el-button>
                          <el-button style="width:72px" v-if="Msg_type=='21' && Msgdata.length >0 " @click="$router.push('/NBS513');showsxkmsg=false">反馈</el-button>
                          <el-button style="width:72px" v-if="(Msg_type=='13'|| Msg_type=='OTHER') && Msgdata.length >0 " @click="Batch_read">已阅</el-button>
                      </td>
                      <td style="width:80px">
                          <el-button style="width:72px" @click.native="showsxkmsg=false">退出</el-button>
                      </td>
                  </tr>
              </table>

          </div>
          <div style="height:500px">
              <vxe-table show-overflow ref="xTable" :data.sync="Msgdata" width="100%" height="100%" border size="mini" :select-config="{ reserve: true }" highlight-current-row show-header-overflow resizable header-align="center" :edit-config="{ trigger: 'click', mode: 'cell',showStatus: false,
          showIcon: false,   }" key="1" :loading="Mloading" stripe>
                  <vxe-table-column type="selection" width="40" header-align="center" align="center" v-if="Msg_type=='08'||  Msg_type=='OTHER'"> </vxe-table-column>
                  <vxe-table-column field="msgsendtime" title="消息时间" width="120" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']" align="center"></vxe-table-column>
                  <vxe-table-column field="msgtype" title="消息类型" width="70" align="center" :edit-render="{name:'select', options: Msg_types}"></vxe-table-column>
                  <vxe-table-column field="msgtitle" title="消息内容" width="300"></vxe-table-column>
                  <vxe-table-column field="msgsender" title="发送人" width="60" align="center"> </vxe-table-column>
                  <vxe-table-column field="pat_no" title="病历号" width="100" align="left" header-align="center"></vxe-table-column>
                  <vxe-table-column field="pat_name" title="姓名" width="60" align="center" header-align="center"></vxe-table-column>
                  <vxe-table-column field="id" title="相关ID" width="30" align="let" header-align="center"></vxe-table-column>
                  <vxe-table-column field="msgid" title="消息ID" width="30" align="let" header-align="center"></vxe-table-column>
                  <vxe-table-column field="msgcontent" title="消息内容" width="120" align="center"></vxe-table-column>
                  <template v-slot:fix>
                      <div style="font-size:17px;padding-top:3px;background-color:#fff;text-align:center;font-weight:bold;color:blue">共 {{datacnt}} 条</div>
                  </template>
              </vxe-table>

          </div>

      </el-dialog> -->
      <audio ref="wavaudio" :src="wavUrl" width="0" height="0" loop></audio>
  </div>
</template>
<script>
// import pdf from "vue-pdf";
import RmInvalert from "@/components/rmcompents/rminv/rm_invalert.vue";
import RmDevalert from "@/components/rmcompents/rmdev/rm_devalertinfo.vue";
import RmBactalert from "@/components/rmcompents/rmsampleinfo/rm_bactalert.vue";
import RmNbsalert from "@/components/rmcompents/rmnbs/rm_nbsalert.vue";
import RmMsgalert from "@/components/rmcompents/msgcenter/msgcenter.vue";
import RmReqchargealertinfo from "@/components/rmcompents/msgcenter/rm_reqchargealertinfo.vue";
import RmBldchargealertinfo from "@/components/rmcompents/rmnbs/rm_bldchargealert.vue";
import RmScurityalertinfo from "@/components/rmcompents/msgcenter/rm_scurityalertinfo.vue";
import RmReportalert from "@/components/rmcompents/msgcenter/rm_reportalertinfo.vue";
import RmMsgcenterpage from "@/components/page/msgcenter_page.vue";

export default {
  components: {
      // pdf,
      RmBactalert,
      RmInvalert,
      RmDevalert,
      RmNbsalert,
      RmMsgalert,
      RmReqchargealertinfo,
      RmBldchargealertinfo,
      RmScurityalertinfo,
      RmReportalert,
      RmMsgcenterpage,
  },
  // provide(){
  //     reload: this.reload();
  // },
  data: function () {
      return {
          message: "",
          // prePDFVisible: false,
          // pdfPages: 1,
          // url: "",
          // vuePdf: "",
          timeoutid: 0,
          locktime: 0,
          scurity: {
              safeflag: false,
              waittime: 0,
              timeoutid: 0,
              dialogscurity: false,
              scuritykey: 0,
          },
          networkAlertMsg: false,
          ruimeiwaitreloading: false,
          msgRunning: [],
          bactalertVisible: false,
          invalertVisible: false,
          nbsalertVisible: false,
          devhandexeVisible: false,
          sampleList: [],
          expirydata: [],
          exceeddata: [],
          fewerdata: [],
          overtimedata: [],
          stocklimitdata: [],
          specdata: [],
          havedataqty: 0,
          devobj: { tabledata: [] },
          msgobj: { msgdialog: false, msgkey: 0, params: {} },
          showsxkmsg: false,
          Mloading: false,
          Msgdata: [], //显示的数据
          Msgalldata: [], // 所有的消息
          Msg_type: "ALL",
          Msg_cnt: { cnt: 0, checkcnt: 0, rcvcnt: 0, noticecnt: 0, othercnt: 0, buliangcnt: 0, pijiacnt: 0 },
          Msg_types: [
              { value: "08", label: "待接收" },
              { value: "04", label: "待审核" },
              { value: "21", label: "不良反应" },
              { value: "15", label: "待评价" },
              { value: "13", label: "用血通知" },
              { value: "99", label: "申请单作废" },
              { value: "96", label: "申请单终止" },
          ],
          //总数,  待审核, 待接收,  用血通知,,其他, 待反馈, 待评价
          reqchargeobj: { msgdialog: false, reqchargedatas: [], params: {} },
          Bldchargeobj: { msgdialog: false, bldchargedatas: [], params: {},setdata:[] },
          rptadmin: "", //计价失败提醒允许上报管理员，由管理员处理
          checkReportVisible: false,
          reportobj: { tabledata: [] },
          mustmsgobj: {
              confirmVisible: false,
              confirmkey: 0,
              tableData: {},
          },
          msgalertwithspeek: "",//消息弹窗提醒同时语音提醒
          wavUrl: require("@/assets/vedio/alert.wav"),
      };
  },
  created() {
      this.QueryHospName();
      let pmv = localStorage.getItem("RMPageScale");
      //先兼容现在的，等将来和壳配合好了之后再使用
      if (pmv && pmv >= 1) {
          if (typeof jsObj != "undefined") {
              pmv = pmv.toString();
              jsObj.SetScale(pmv);
          } else {
              document.body.style.zoom = pmv;
          }
      }
      // this.vuePdf = require("vue-pdf");
  },
  computed: {
      datacnt() {
          return this.Msgdata.length;
      },
  },
  mounted() {
      let that = this;
      window.procBrowserMsg = this.procBrowserMsg; //第三方调用门诊采样时，浏览器壳发过来的消息
      window.savecasign = this.savecasign; //CA签名回调函数
      window.imagecatch = this.imagecatch; //测试图像捕获回调
      // this.$bus.$on("prePDFDialog", (url) => {
      //     this.prePDFDialogShow(url);
      // });
      this.$bus.$on("bactAlert", (sampleList) => {
          this.sampleList = sampleList;
          this.bactalertVisible = true;
      });
      this.$bus.$on("networkchange", (flag) => {
          that.networkAlertMsg = !flag;
      });
      this.$bus.$on("ruimeiwaitreloading", (flag) => {
          that.ruimeiwaitreloading = true;
      });
      this.$bus.$on("getmsgsetting", (setting) => {
          that.noticemsgsetting = setting;
      });
      this.$bus.$on("msgnotice", (msgcount) => {
          if (!that.$tool.msgReadLock) {
              that.$tool.msgReadLock = true;
              that.$tool
                  .request({
                      url: "ucent/getmsg",
                      method: "post",
                      data: {
                          userno: that.$pub.getuser(that, 1),
                          mac: that.$pub.getmac(),
                      },
                  })
                  .then((res) => {
                      // console.log("res", res);

                      //前台校验所接收的消息是不是本人的消息
                      //收到消息，如果和之前一样的不动，多的添加，少的清除
                      let msgJsons = [];
                      for (let i = 0; i < res.length; i++) {
                          let tmj = JSON.stringify(res[i]);
                          if (msgJsons.findIndex((m) => m == tmj) < 0) {
                              msgJsons.push(tmj);
                          }
                      }

                      let tempmsgFilter = [];
                      let toclose = [];
                      for (let i = 0; i < that.msgRunning.length; i++) {
                          let mritem = that.msgRunning[i];
                          if (msgJsons.findIndex((m) => m == mritem.k) < 0) {
                              toclose.push(mritem);
                          } else {
                              tempmsgFilter.push(mritem);
                          }
                      }
                      that.msgRunning = tempmsgFilter;

                      for (let i = 0; i < toclose.length; i++) {
                          let mritem = toclose[i];
                          if (mritem.v) {
                              // console.log("autoclose", mritem.k);
                              if (mritem.v == "true") {
                                  that.reqchargeobj.msgdialog = false;
                                  that.mustmsgobj.confirmVisible = false;
                              } else {
                                  mritem.v.close();
                              }
                          }
                      }

                      let tempmsgRunning = [];
                      for (let i = 0; i < msgJsons.length; i++) {
                          let msgitemjson = msgJsons[i];
                          let tempindex = that.msgRunning.findIndex((m) => m.k == msgitemjson);
                          if (tempindex >= 0) {
                              tempmsgRunning.push(that.msgRunning[tempindex]);
                          } else {
                              tempmsgRunning.push({ k: msgitemjson, v: null, t: Date.now() });
                          }
                      }
                      that.msgRunning = tempmsgRunning;
                      that.msgDisplayLoop(); //消息显示或关闭
                      // console.log("111", that.msgRunning);
                  })
                  .catch((erro) => {});
              setTimeout(() => {
                  that.$tool.msgReadLock = false;
              }, 1000);
          }
      });
      this.$bus.$on("clearmsgnotice", (m) => {
          let that = this;
          //清空数组，关闭所有消息

          let toclose = [];
          for (let i = 0; i < that.msgRunning.length; i++) {
              let msgRunItem = that.msgRunning[i];
              if (msgRunItem.v) {
                  toclose.push(msgRunItem);
              }
          }
          that.msgRunning = [];
          //弹窗消息一次只能显示一个，关闭这里直接设置false也可以
          that.reqchargeobj.msgdialog = false;
          for (let i = 0; i < toclose.length; i++) {
              let mritem = toclose[i];
              if (mritem.v) {
                  if (mritem.v == "true") {
                      that.reqchargeobj.msgdialog = false;
                  } else {
                      mritem.v.close();
                  }
              }
          }
          //没有消息了，铃铛也要取消摆动
          that.$bus.$emit("headermsgshake", 0);
      });
      //商品过期信息,低于安全库存警告信息，库存超限警告信息提醒
      this.$bus.$on("invAlert", (res) => {
          this.havedataqty = 0;
          this.expirydata = res.expirydata;
          if (res.expirydata.length > 0) {
              this.havedataqty++;
          }
          this.exceeddata = res.exceeddata;
          if (res.exceeddata.length > 0) {
              this.havedataqty++;
          }
          this.fewerdata = res.fewerdata;
          if (res.fewerdata.length > 0) {
              this.havedataqty++;
          }
          if (this.havedataqty > 0) {
              this.invalertVisible = true;
          }
      });
      this.$bus.$on("BldchargeAlert", (res) => {
          // 输血科异常信息提示
          //  console.log("计价失败提示");
          if (this.Bldchargeobj.msgdialog) return;
          let _data = res.bldchargealertdata; // 计价失败提示信息
          if (_data.length > 0) {
              this.Bldchargeobj.setdata = res.setdata;
              this.Bldchargeobj.bldchargedatas = _data;
              this.Bldchargeobj.msgdialog = true;
          }

      });
      this.$bus.$on("NbsAlert", (res, showflag) => {
          // 输血科异常信息提示
          if (showflag == false) {
              this.nbsalertVisible = false;
              return;
          }
          //if (this.nbsalertVisible) return;

          this.havedataqty = 0;

          let that = this;
          // 判断当前工作站以及全局变量, 是否禁用弹窗
          that.overtimedata = res.expirydata;
          //  console.log("过期血液" + that.overtimedata + that.overtimedata.length);
          if (that.overtimedata.length > 0) {
              that.havedataqty++;
          }
          that.stocklimitdata = res.fewerdata;
          //  console.log("安全库存" + that.stocklimitdata);
          if (that.stocklimitdata.length > 0) {
              that.havedataqty++;
          }

          that.specdata = res.exceeddata;
          //   console.log("异常血液" + that.specdata);
          if (that.specdata.length > 0) {
              that.havedataqty++;
          }
          if (that.havedataqty > 0) {
              that.nbsalertVisible = true;
          }
      });
      // this.$bus.$on("BisPopmsg", res => {
      //     if (res.length > 0) {
      //         // Msg_cnt:{cnt:0, checkcnt:0,rcvcnt:0,notice:0,othercnt:0,buliangcnt:0,pijiacnt:0},
      //         this.Msg_type = "ALL";
      //         this.Msgalldata = res;
      //         this.Msgdata = this.Msgalldata.filter(m => m.msgtype != "");
      //         let ll_cnt = this.Msgalldata.length;
      //         let ll_ncnt = this.Msgalldata.filter(m => m.msgtype == "08").length;
      //         this.Msg_cnt.cnt = ll_cnt;
      //         this.Msg_cnt.rcvcnt = ll_ncnt;
      //         ll_cnt = ll_cnt - ll_ncnt;
      //         ll_ncnt = this.Msgalldata.filter(m => m.msgtype == "04" || m.msgtype == "54" || m.msgtype == "62" || m.msgtype == "65").length;
      //         this.Msg_cnt.checkcnt = ll_ncnt;
      //         ll_cnt = ll_cnt - ll_ncnt;
      //         ll_ncnt = this.Msgalldata.filter(m => m.msgtype == "13").length;
      //         this.Msg_cnt.noticecnt = ll_ncnt;
      //         ll_cnt = ll_cnt - ll_ncnt;
      //         ll_ncnt = this.Msgalldata.filter(m => m.msgtype == "15").length;
      //         this.Msg_cnt.pijiacnt = ll_ncnt;
      //         ll_cnt = ll_cnt - ll_ncnt;
      //         ll_ncnt = this.Msgalldata.filter(m => m.msgtype == "21").length;
      //         this.Msg_cnt.buliangcnt = ll_ncnt;
      //         ll_cnt = ll_cnt - ll_ncnt;
      //         this.Msg_cnt.othercnt = ll_cnt;
      //         this.showsxkmsg = true;
      //     }
      // });
      this.$bus.$on("DevAlert", (res) => {
          //console.log("app", res.data);
          this.devobj.tabledata = res.data;
          this.devobj.plankey++;
          if (res.waitplancnt > 0) this.devhandexeVisible = true;
      });

      this.$bus.$on("ReportAlert", (res) => {
          //console.log("reportobj", res.data);
          this.reportobj.tabledata = res.data;
          this.reportobj.reportkey++;
          if (res.waitreportcnt > 0) this.checkReportVisible = true;
      });

      // this.msgDisplayLoop(); 不需要循环监控了，有消息的时候触发一次显示
      this.RefreshLock();
  },
  methods: {
      imagecatch(p1, p2, p3) {
          console.log("p1,p2,p3", p1[0], p1[1000], p3);
          this.$bus.$emit("imagecatch", p1);
      },
      savecasign(reportid, signjson) {
          this.$ca.savecasign(this, reportid, signjson);
      },
      async procBrowserMsg(data) {
          try {
              console.log("procBrowserMsg");
              this.$tool.removeSession(this.$tool.otherparam);
              let menu = this.$route.fullPath;
              // console.log("menu", menu);
              // if(menu.indexOf()) u=admin&c=2&p1=123
              //拆分参数
              //var p = this.$pub.geturlparam(data);
              var paramstr = this.$pub.geturlparamjson(data);
              var p = JSON.parse(paramstr);
              let setemit = true;
              if (p) {
                  this.$tool.setSession(this.$tool.otherparam, paramstr);
                  if (!!p.u && p.u != this.$tool.getSession(this.$tool.loginuserno)) {
                      //第三方传入用户发生了变化
                      let userno = p.u;
                      let res = await this.$tool.request({
                          url: "/ucent/login",
                          method: "post",
                          data: {
                              action: "thirdlogin",
                              ...p,
                          },
                      });
                      if (res && res.flag == 1) {
                          this.$tool.setSession(this.$tool.loginusername, res.username);
                          this.$tool.setSession(this.$tool.loginuserno, res.userno);
                          this.$tool.setSession(this.$tool.logintoken, res.msg);
                      }
                  }
                  if (p.c == "2") {
                      //调用门诊采血
                      this.$tool.setLocalConfig("bigmodel", "REQ");
                      this.$bus.$emit("switchmodel", "REQ");
                      // this.$router.push("/REQ110");
                      if (menu && menu.indexOf("REQ110") < 0) {
                          this.$router.push("/REQ110");
                          //setemit = false;
                      }
                  } else if (p.c == "1") {
                      //调用自助取单
                      this.$tool.setLocalConfig("bigmodel", "LIS");
                      this.$bus.$emit("switchmodel", "LIS");
                      // this.$router.push("/LIS420");
                      if (menu && menu.indexOf("LIS420") < 0) {
                          this.$router.push("/LIS420");
                          //setemit = false;
                      }
                  }
                  if (setemit) {
                      this.$bus.$emit("browsermsg", p);
                  }
              }
          } catch (e) {
              console.log("err", e);
          }
      },
      msgDisplayLoop() {
          let that = this;
          that.$bus.$emit("headermsgshake", that.msgRunning.length);
          //console.log("that.msgRunning", that.msgRunning);
          let msgToDisplay = that.msgRunning.find((m) => {
              let item = JSON.parse(m.k);
              let thisloginignorealertlist = JSON.parse(that.$tool.getSession("thisloginignorealertlist"));
              //加入了本次登录不再提醒列表的，也不再提醒了
              if (thisloginignorealertlist) return !m.v && (thisloginignorealertlist.indexOf(item.msgtype) < 0);
              else return !m.v;
          });
          //console.log("msgToDisplay", msgToDisplay);
          if (msgToDisplay) {
              let msgitem = JSON.parse(msgToDisplay.k);
              //（1表示消息直接弹窗 0表示消息通过点击消息通知弹窗）
              if (msgitem.msgmode == "1") {
                  msgToDisplay.v = "true"; //赋值 表示消息已经显示
                  // 弹窗类的消息，一次只能弹一个
                  // console.log("msgmode", msgitem.msgmode);
                  if (msgitem.paramlist.p1 == "4") {
                      //申请单计价失败消息初始化
                      that.initReqChargeData(that, msgitem)
                          .then((res) => {
                              if (res.data && res.data.length > 0) {
                                  that.reqchargeobj.reqchargedatas = res.data;
                                  that.reqchargeobj.params = msgitem;
                                  this.rptadmin = res.rptadmin;
                                  this.reqchargeobj.msgdialog = true;
                              }
                          })
                          .catch((e) => {});
                  } else if (msgitem.paramlist.p1 == "16") {
                      //必须确认消息弹窗提醒
                      that.initMsgdata(that, msgitem)
                          .then((res) => {
                              // console.log("889", res);
                              if (res.data && res.data.length > 0) {
                                  that.mustmsgobj.tableData = res.data;
                                  that.mustmsgobj.confirmkey++;
                                  that.mustmsgobj.confirmVisible = true;
                              }
                          })
                          .catch((e) => {});
                  }
              } else {
                  const h = that.$createElement;
                  var setting = {};
                  var alertcolor = "#000000";
                  if(that.noticemsgsetting && that.noticemsgsetting.length >0) {
                      setting = that.noticemsgsetting.find(item=>item.msgtype == msgitem.msgtype);
                  }
                  if(!!setting) alertcolor = setting.msgcolor;
                  let showmsg = {
                      title: msgitem.title,
                      dangerouslyUseHTMLString: true,
                      position: "bottom-right",
                      message: h(
                          "div",
                          {
                              attrs: {
                                  style: "cursor:pointer;color:" + alertcolor +";",
                              },
                              on: {
                                  click: ($event) => {
                                      console.log("murl", msgitem);
                                      switch (msgitem.showmode) {
                                          case "1": //全屏窗口()
                                              this.$router.push({ path: "/msgcenter_page", query: msgitem.paramlist });
                                              break;
                                          case "2": //弹窗
                                              this.msgobj.params = msgitem;
                                              this.msgobj.msgkey++;
                                              this.msgobj.msgdialog = true;
                                              break;
                                          default:
                                              break;
                                      }
                                  }, // 路由加载之后，调用关闭消息弹窗的方法
                              },
                          },
                          that.$pub.contrltextnum(msgitem.msgcontent, 40)
                      ),

                      duration: msgitem.autoclose,
                      onClose: () => {
                          that.noticeClose(msgToDisplay.k);
                      },
                  };

                  if (msgitem.msglevel == 1) {
                      showmsg.type = "warning";
                      msgToDisplay.v = that.$notify(showmsg);
                  } else if (msgitem.msglevel == 0) {
                      msgToDisplay.v = that.$notify.info(showmsg);
                  } else {
                      msgToDisplay.v = that.$notify.error(showmsg);
                  }

                  if(!!setting && setting.onsound == "1") {
                      //如果没有设置直接用默认的
                      // if(setting.soundname) that.wavUrl = require("@/assets/vedio/" + setting.soundname);
                      // console.log(that.wavUrl, '111111111');
                      //要先等音频加载完才能播放
                      setTimeout(() => {
                          that.$refs.wavaudio.play();
                      }, 100);
                      //声音持续设置的时间后停止
                      setTimeout(() => {
                          that.$refs.wavaudio.pause();
                      }, setting.soundtime*1000);
                  }
              }
              setTimeout(() => {
                  that.msgDisplayLoop();
              }, 1000);
          }
      },
      networkAlertConfirm() {
          this.networkAlertMsg = false;
      },
      waitReloadConfirm() {
          location.reload();
      },
      noticeClose(data, nomoreflag) {
          let that = this;
          // console.log("nomoreflag", nomoreflag);
          let tindex = that.msgRunning.findIndex((m) => m.k == data);
          if (tindex >= 0) {
              try {
                  if (nomoreflag == "1") {
                      that.msgRunning.splice(tindex, 1);
                  } else {
                      //消息关闭，并不删除消息
                      that.msgRunning[tindex].v = null;
                      setTimeout(() => {
                          //同时延后1分钟再触发消息显示逻辑，关闭消息后，1分钟后再根据后台消息来判断是否显示消息
                          that.msgDisplayLoop();
                      }, 60000);
                      this.emptyNoticeCache(data);
                  }
                  //that.msgRunning.splice(tindex, 1);
              } catch (e) {}
          }
          // console.log("close", that.msgRunning);
      },
      emptyNoticeCache(msgitem){
          var msgitemjson =JSON.parse(msgitem)
          //console.log("msgitemjson",msgitemjson)
          this.$tool
              .request({
                  url: "ucent/alertclose",
                  method: "post",
                  data: {
                      params: msgitemjson.paramlist,
                  },
              })
              .then((res) => {
                   console.log("清空消息缓存",res);
              });
      },
      QueryHospName() {
          this.$tool
              .request({
                  url: "ucent/login",
                  method: "post",
                  data: {
                      action: "loginname",
                  },
              })
              .then((response) => {
                  if (response.errcode == "1") {
                      if (response.cname) {
                          window.document.title = response.cname;
                      }
                      if (response.locktime) {
                          this.locktime = response.locktime;
                      }
                      this.scurity.waittime = response.waittime;
                      this.scurity.safeflag = response.safeflag == "1";
                      this.noticemsgsetting = response.noticemsgsetting;//消息提醒设置
                      // console.log("11", this.scurity);
                  }
              });
      },
      //计时器一小时没有操作退回登陆界面
      //暂时屏蔽，增加本地选项后打开
      RefreshLock() {
          //alert(this.locktime);
          clearTimeout(this.timeoutid);
          if (this.locktime && this.locktime > 0) {
              this.timeoutid = setTimeout(() => {
                  this.$router.push("/login");
                  //console.log("rlock");
              }, (this.locktime - 0) * 60 * 1000);
          }
          //console.log("sa", this.scurity);
          
          clearTimeout(this.scurity.timeoutid);
          if (this.scurity.safeflag) {
              //启用安全保护
              if (this.scurity.waittime && this.scurity.waittime > 0) {
                  this.scurity.timeoutid = setTimeout(() => {
                      if (!!this.$tool.getSession(this.$tool.loginuserno)) {
                          this.scurity.dialogscurity = true;
                          this.scurity.scuritykey++;
                      }
                  }, (this.scurity.waittime - 0) * 1000);
              }
          } else {
              this.scurity.dialogscurity = false;
              this.scurity.scuritykey = 0;
          }
      },
      // prePDFDialogShow(url) {
      //     this.url = this.vuePdf.default.createLoadingTask(url);
      //     this.url.promise.then((pdf) => {
      //         this.pdfPages = pdf.numPages;
      //         this.url = url;
      //         this.prePDFVisible = true;
      //     });
      // },
      // clearPrePDF() {
      //     this.pdfPages = 1;
      //     this.url = "";
      // },

      //初始化申请单计价失败提醒信息
      initReqChargeData(that, msgitem) {
          return that.$tool.request({
              url: "ucent/alertmsg",
              method: "post",
              data: {
                  params: msgitem.paramlist,
              },
          });
      },
      //初始化必须确认消息提醒信息
      initMsgdata(that, msgitem) {
          return that.$tool.request({
              url: "ucent/alertmsg",
              method: "post",
              data: {
                  params: msgitem.paramlist,
              },
          });
      },
      //关闭弹窗消息处理（直接弹窗的消息)
      CloseMsgHandle(flag, params, nomoreflag) {
          //console.log(flag,params);
          if (flag == "reqcharge") {
              this.noticeClose(JSON.stringify(params), nomoreflag);
              this.reqchargeobj.msgdialog = false;
          }
          if (flag == "bldcharge") {
              this.noticeClose(JSON.stringify(params));
              this.Bldchargeobj.msgdialog = false;
          }
      },
      scurityEvent(event) {
          if (event == "logoff") {
              this.$tool.removeSession(this.$tool.loginuserno);
              this.$tool.removeSession(this.$tool.loginusername);
              this.$tool.removeSession(this.$tool.logintoken);
              this.$ddldata.msgparm.localReqChargedt = "";
              this.$tool.removeSession("noreg");
              sessionStorage.removeItem("buttonpremissions");
          }
          this.scurity.dialogscurity = false;
          this.RefreshLock();
      },
  },
  beforeDestroy() {
      this.$bus.$off("bactAlert");
      this.$bus.$off("BldchargeAlert");
      this.$bus.$off("clearmsgnotice");
      this.$bus.$off("DevAlert");
      this.$bus.$off("ReportAlert");
      this.$bus.$off("invAlert");
      this.$bus.$off("msgnotice");
      this.$bus.$off("NbsAlert");
      this.$bus.$off("networkchange");
      this.$bus.$off("ruimeiwaitreloading");
      this.$bus.$off("getmsgsetting");
  },
};
</script>
<style>
@import "./assets/css/main.css";

@import "./assets/css/color-dark.css"; /*深色主题*/
/*@import "./assets/css/theme-green/color-green.css";浅绿色主题*/
@import "./assets/css/icon.css";
@import "./assets/icon/iconfont.css";

/* .el-menu--horizontal{
  overflow-y: auto;
  height: calc(100% - 35px);
} */


::v-deep  .scurityclass .el-dialog__body {
  padding: 0;
  height: 360px;
  overflow: hidden;
}

::v-deep  .scurityclass .el-dialog__header {
  padding: 0;
}
</style>
